using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TanashCMS.Business;
using System.IO;

public partial class oops : System.Web.UI.Page
{
    protected override void OnPreInit(EventArgs e)
    {
        // set the master page for the site
        // make sure the error was not thrown by another instance of this page however
        // or we might create an infinite loop
        //
        TanashWebsite mWebsite = null;
        if (Request.QueryString["aspxerrorpath"].IndexOf("/errors/") < 0)
        {
            // determine what website this is based on the hostname
            HttpContext context = HttpContext.Current;
            Uri uri = context.Request.Url;

            // find the hostname
            string[] domain = uri.Host.Split('.');
            string hostname = uri.Host;
            if (hostname.Substring(0, 4) == "www.")
                hostname = hostname.Substring(4);

            mWebsite = TanashWebsite.GetByHostName(hostname);

            if (mWebsite != null)
            {
                string masterFilePath = Server.MapPath(Request.ApplicationPath.TrimEnd('/') + "/MasterPages/" + mWebsite.SubFolderName + "/default.master");
                string masterFileUrl = Request.ApplicationPath.TrimEnd('/') + "/MasterPages/" + mWebsite.SubFolderName + "/default.master";
                if (File.Exists(masterFilePath))
                    Page.MasterPageFile = masterFileUrl;
            }
        }
        base.OnPreInit(e);
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }
}
